import React, { Component } from 'react'
import auth from './auth'
import { Route, Redirect } from 'react-router-dom'

export default class AuthRouterGuard extends Component {

  render(props) {
    console.log(this.props)
    const { Component, ...params } = this.props
    console.log(params, '==============')
    return (
      <Route {...params} render={(props) => {
        console.log(auth.isAuthorized())
        if (!auth.isAuthorized()) {
          // 重定向
          return <Redirect to="/home"></Redirect>
        } else {
          // 注意，参数传递形式
          return <Component {...params} {...props}/>
        }
      }} />
    )
  }
}